package com.zty.xiaomiadmin.server.Controller;


import com.sun.org.apache.xpath.internal.objects.XString;
import com.zty.xiaomiadmin.server.Entity.Report.Report;
import com.zty.xiaomiadmin.server.Entity.Report.ReportPie;
import com.zty.xiaomiadmin.server.Entity.Report.ReportPieResult;
import com.zty.xiaomiadmin.server.Entity.Report.ReportResult;
import com.zty.xiaomiadmin.server.Service.Report.ReportService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

@CrossOrigin
@RestController
@RequestMapping("report")
public class ReportController {
    @Autowired
    private ReportService reportService;

    @RequestMapping("/getMonthReport")
    public ReportResult getMonthReport(){
        try {
            List<Report> reportList = reportService.getMonthData();
            return new ReportResult(200,"查询成功",reportList);
        }catch (Exception e){
            e.printStackTrace();
            return new ReportResult(500,"查询失败",null);
        }
    }

    @RequestMapping("/getReportDataByMonth")
    public ReportResult getReportDataByMonth(String date){
        try {
            List<Report> reportList = reportService.getReportDataByMonth(date);
            return new ReportResult(200,"查询成功",reportList);
        }catch (Exception e){
            e.printStackTrace();
            return new ReportResult(500,"查询失败",null);
        }
    }

    @RequestMapping("/getReportDataByMonthPay")
    public ReportResult getReportDataByMonthPay(String date){
        try {
            List<Report> reportList = reportService.getReportDataByMonthPay(date);
            return new ReportResult(200,"查询成功",reportList);
        }catch (Exception e){
            e.printStackTrace();
            return new ReportResult(500,"查询失败",null);
        }
    }

    @RequestMapping("/getReportDataByMonthCancel")
    public ReportResult getReportDataByMonthCancel(String date){
        try {
            List<Report> reportList = reportService.getReportDataByMonthCancel(date);
            return new ReportResult(200,"查询成功",reportList);
        }catch (Exception e){
            e.printStackTrace();
            return new ReportResult(500,"查询失败",null);
        }
    }

    @RequestMapping("/getReportDataByMonthPIE")
    public ReportPieResult getReportDataByMonthPIE(String date){
        try {
            List<ReportPie> reportPieList = reportService.getReportDataByMonthPIE(date);
            return new ReportPieResult(200,"查询成功",reportPieList);
        }catch (Exception e){
            e.printStackTrace();
            return new ReportPieResult(500,"查询失败",null);
        }
    }

    @RequestMapping("/getReportDataByQuarter")
    public ReportPieResult getReportDataByQuarter(String date, int quarter){
        List<String> list=new ArrayList<>();
        if (quarter ==1){
            list.add(date+"-01");
            list.add(date+"-02");
            list.add(date+"-03");
        }else if (quarter == 2){
            list.add(date+"-04");
            list.add(date+"-05");
            list.add(date+"-06");
        }else if (quarter == 3){
            list.add(date+"-07");
            list.add(date+"-08");
            list.add(date+"-09");
        }else if (quarter == 4){
            list.add(date+"-10");
            list.add(date+"-11");
            list.add(date+"-12");
        }
        try {
            List<ReportPie> reportList = reportService.getReportDataByQuarter(list);
            return new ReportPieResult(200,"查询成功",reportList);
        }catch (Exception e){
            e.printStackTrace();
            return new ReportPieResult(500,"查询失败",null);
        }
    }
    @RequestMapping("/getReportDataByQuarterPay")
    public ReportPieResult getReportDataByQuarterPay(String date, int quarter){
        List<String> list=new ArrayList<>();
        if (quarter ==1){
            list.add(date+"-01");
            list.add(date+"-02");
            list.add(date+"-03");
        }else if (quarter == 2){
            list.add(date+"-04");
            list.add(date+"-05");
            list.add(date+"-06");
        }else if (quarter == 3){
            list.add(date+"-07");
            list.add(date+"-08");
            list.add(date+"-09");
        }else if (quarter == 4){
            list.add(date+"-10");
            list.add(date+"-11");
            list.add(date+"-12");
        }
        try {
            List<ReportPie> reportList = reportService.getReportDataByQuarterPay(list);
            return new ReportPieResult(200,"查询成功",reportList);
        }catch (Exception e){
            e.printStackTrace();
            return new ReportPieResult(500,"查询失败",null);
        }
    }
    @RequestMapping("/getReportDataByQuarterCancel")
    public ReportPieResult getReportDataByQuarterCancel(String date,int quarter){
        List<String> list=new ArrayList<>();
        if (quarter ==1){
            list.add(date+"-01");
            list.add(date+"-02");
            list.add(date+"-03");
        }else if (quarter == 2){
            list.add(date+"-04");
            list.add(date+"-05");
            list.add(date+"-06");
        }else if (quarter == 3){
            list.add(date+"-07");
            list.add(date+"-08");
            list.add(date+"-09");
        }else if (quarter == 4){
            list.add(date+"-10");
            list.add(date+"-11");
            list.add(date+"-12");
        }
        try {
            List<ReportPie> reportList = reportService.getReportDataByQuarterCancel(list);
            return new ReportPieResult(200,"查询成功",reportList);
        }catch (Exception e){
            e.printStackTrace();
            return new ReportPieResult(500,"查询失败",null);
        }
    }

    @RequestMapping("/getReportDataByQuarterPIE")
    public ReportPieResult getReportDataByQuarterPIE(String date,int quarter){
        System.out.println(date+"----"+quarter);
        List<String> list=new ArrayList<>();
        if (quarter ==1){
            list.add(date+"-01");
            list.add(date+"-02");
            list.add(date+"-03");
        }else if (quarter == 2){
            list.add(date+"-04");
            list.add(date+"-05");
            list.add(date+"-06");
        }else if (quarter == 3){
            list.add(date+"-07");
            list.add(date+"-08");
            list.add(date+"-09");
        }else if (quarter == 4){
            list.add(date+"-10");
            list.add(date+"-11");
            list.add(date+"-12");
        }
        try {
            List<ReportPie> reportPieList = reportService.getReportDataByQuarterPIE(list);
            return new ReportPieResult(200,"查询成功",reportPieList);
        }catch (Exception e){
            e.printStackTrace();
            return new ReportPieResult(500,"查询失败",null);
        }
    }
    //年度
    @RequestMapping("/getReportDataByYear")
    public ReportResult getReportDataByYear(String date){
        try {
            List<Report> reportList = reportService.getReportDataByYear(date);
            return new ReportResult(200,"查询成功",reportList);
        }catch (Exception e){
            e.printStackTrace();
            return new ReportResult(500,"查询失败",null);
        }
    }

    @RequestMapping("/getReportDataByYearPay")
    public ReportResult getReportDataByYearPay(String date){
        try {
            List<Report> reportList = reportService.getReportDataByYearPay(date);
            return new ReportResult(200,"查询成功",reportList);
        }catch (Exception e){
            e.printStackTrace();
            return new ReportResult(500,"查询失败",null);
        }
    }

    @RequestMapping("/getReportDataByYearCancel")
    public ReportResult getReportDataByYearCancel(String date){
        try {
            List<Report> reportList = reportService.getReportDataByYearCancel(date);
            return new ReportResult(200,"查询成功",reportList);
        }catch (Exception e){
            e.printStackTrace();
            return new ReportResult(500,"查询失败",null);
        }
    }

    @RequestMapping("/getReportDataByYearPIE")
    public ReportPieResult getReportDataByYearPIE(String date){
        try {
            List<ReportPie> reportPieList = reportService.getReportDataByYearPIE(date);
            return new ReportPieResult(200,"查询成功",reportPieList);
        }catch (Exception e){
            e.printStackTrace();
            return new ReportPieResult(500,"查询失败",null);
        }
    }
}
